package cn.studyjava.dubbo.server.util;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

/**
 * <p>
 * Description:
 * </p>
 * 
 * @author: zhangshenglong
 * @version 1.0.0
 * <p>
 * History:
 * -----------------------------------------------
 * @Date: 2017年3月1日下午1:53:09
 * @author: zhangshenglong
 * @version 1.0.0
 * @OP: Create
 * -----------------------------------------------
 * </p>
 *
 * @since
 * @see
 */
public class RandomUtil {
	
	/**
	 * 
	 * @Title: getRandom
	 * @Description: 获取指定范围随机数
	 * @param start
	 * @param end
	 * @return
	 * @return: String
	 */
	public static final String getRandom(int start, int end) {
		try {
			SecureRandom number = SecureRandom.getInstance("SHA1PRNG");
			return String.valueOf(number.nextInt(end - start + 1) + start);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * 测试随机数是否越界
	 */
//	public static void main(String[] args) {
//		for (int i = 0; i < 100000; i++) {
//			String random = getRandom(1,100);
//			if(Integer.parseInt(random) > 100 || Integer.parseInt(random) < 1){
//				System.err.println(random);
//			}
//			System.out.println(random);
//		}
//	}
}
